﻿/*****************************************************************************
 * Hyldahl.Services.TaskProcessing.Test            Created by: MSH 2008.07.22
 * --------------------------------------------------------------------------
 * FileName: TaskTest.cs
 * --------------------------------------------------------------------------
 * Copyright 2009 Martin Sixhøj Hyldahl
 *****************************************************************************/

using NUnit.Framework;
using System;

namespace Hyldahl.Services.TaskProcessing.Test
{
    /// <summary>
    ///This is a test class for TaskTest and is intended
    ///to contain all TaskTest Unit Tests
    ///</summary>
    [TestFixture()]
    public class TaskTest
    {
        /// <summary>
        ///A test for TaskType
        ///</summary>
        [Test()]
        public void TaskTypeTest()
        {
            Task target = new Task();
            string expected = "The Task Type Property";
            string actual   = "The Task Type Property";

            target.TaskType = expected;
            actual          = target.TaskType;
            
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ResultData
        ///</summary>
        [Test()]
        public void ResultDataTest()
        {
            Task target = new Task();
            string expected = "The Result Data";
            string actual   = "The Result Data";

            target.ResultData   = expected;
            actual              = target.ResultData;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ReadDate
        ///</summary>
        [Test()]
        public void ReadDateTest()
        {
            Task target = new Task();

            DateTime? expected = null;
            DateTime? actual   = null;

            target.ReadDate = expected;
            actual          = target.ReadDate;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ReadDate
        ///</summary>
        [Test()]
        public void ReadDateTest2()
        {
            Task target = new Task();

            DateTime date = DateTime.Now;

            DateTime? expected = date;
            DateTime? actual   = date;

            target.ReadDate = expected;
            actual          = target.ReadDate;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for ProcessingTime
        ///</summary>
        [Test()]
        public void ProcessingTimeTest()
        {
            Task target = new Task();

            long? expected   = 10;
            long? actual     = 10;

            target.ProcessingTime   = expected;
            actual                  = target.ProcessingTime;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for IsProcessed
        ///</summary>
        [Test()]
        public void IsProcessedTest()
        {
            Task target = new Task();
            
            bool expected   = true;
            bool actual     = true;

            target.IsProcessed  = expected;
            actual              = target.IsProcessed;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Id
        ///</summary>
        [Test()]
        public void IdTest()
        {
            Task target = new Task();

            Guid id = Guid.NewGuid();

            Guid expected   = id;
            Guid actual     = id;

            target.Id   = expected;
            actual      = target.Id;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Data
        ///</summary>
        [Test()]
        public void DataTest()
        {
            Task target = new Task();

            string expected = string.Empty;
            string actual;

            target.Data = expected;
            actual      = target.Data;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CreatedDate
        ///</summary>
        [Test()]
        public void CreatedDateTest()
        {
            Task target = new Task();

            DateTime date = DateTime.Now;

            DateTime expected   = date;
            DateTime actual     = date;

            target.CreatedDate  = expected;
            actual              = target.CreatedDate;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CompletedSuccessfully
        ///</summary>
        [Test()]
        public void CompletedSuccessfullyTest()
        {
            Task target = new Task();

            bool? expected  = true;
            bool? actual    = true;

            target.CompletedSuccessfully    = expected;
            actual                          = target.CompletedSuccessfully;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CompletedDate
        ///</summary>
        [Test()]
        public void CompletedDateTest()
        {
            Task target = new Task();

            DateTime date = DateTime.Now;

            DateTime? expected  = date;
            DateTime? actual    = date;

            target.CompletedDate    = expected;
            actual                  = target.CompletedDate;

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for CompareToTest
        ///</summary>
        [Test()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CompareToNullArgumentTest()
        {
            Task target = new Task();

            target.CompareTo(null);
        }

        /// <summary>
        ///A test for CompareToTest
        ///</summary>
        [Test()]
        public void CompareToTest()
        {
            Task target = new Task();

            target.Id                       = Guid.NewGuid();
            target.IsProcessed              = true;
            target.TaskType                 = "Fibonacci";
            target.Data                     = "500";
            target.CompletedDate            = DateTime.Now;
            target.CompletedSuccessfully    = true;
            target.CreatedDate              = DateTime.Now.AddDays(-1);
            target.ProcessingTime           = 100;
            target.ReadDate                 = DateTime.Now.AddHours(-1);

            Task compare = new Task();

            compare.Id = Guid.NewGuid();
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.Id = target.Id;

            compare.TaskType = "Other task type";
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.TaskType = target.TaskType;

            compare.Data = "SomeData";
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.Data = target.Data;

            target.ResultData = "34053";
            compare.ResultData = null;
            Assert.IsTrue(target.CompareTo(compare) != 0);

            target.ResultData = null;
            compare.ResultData = "Result Data";
            Assert.IsTrue(target.CompareTo(compare) != 0);

            target.ResultData = null;
            compare.ResultData = null;
            Assert.IsTrue(target.CompareTo(compare) != 0); // Other data differs

            target.ResultData = "34053";
            compare.ResultData = "Result Data";
            Assert.IsTrue(target.CompareTo(compare) != 0);

            compare.ResultData = target.ResultData;

            compare.IsProcessed = !target.IsProcessed;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.IsProcessed = target.IsProcessed;

            compare.CreatedDate = DateTime.MinValue;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.CreatedDate = target.CreatedDate;

            compare.CompletedSuccessfully = null;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.CompletedSuccessfully = target.CompletedSuccessfully;

            compare.ProcessingTime = 349802;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.ProcessingTime = target.ProcessingTime;

            compare.ReadDate = null;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.ReadDate = target.ReadDate;

            compare.CompletedDate = null;
            Assert.IsTrue(target.CompareTo(compare) != 0);
            compare.CompletedDate = target.CompletedDate;


            Assert.IsTrue(target.CompareTo(compare) == 0);
        }

        /// <summary>
        ///A test for Task Constructor
        ///</summary>
        [Test()]
        public void TaskConstructorTest()
        {
            Task target = new Task();
        }
    }
}
